package wcg;

import ikelib.wintime;

import javax.swing.JPanel;
import java.awt.Frame;
import java.awt.BorderLayout;
import javax.swing.JDialog;
import javax.swing.JTextField;
import java.awt.Rectangle;
import javax.swing.JLabel;
import java.awt.Dimension;
import javax.swing.JButton;

public class DialogTimeSetting extends JDialog {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JTextField jTextFieldTime = null;
	private JLabel jLabel = null;
	private JButton jButtonOK = null;
	private JButton jButtonCancel = null;
	private setStartTime Parent = null; //@
	private wintime CurrentTime = null;  //  @jve:decl-index=0:
	/**
	 * @param owner
	 */
	public DialogTimeSetting(Frame owner) {
		super(owner);
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(249, 159);
		this.setTitle("Time setting dialog");
		this.setContentPane(getJContentPane());
	}
	//public void setParent(GraphicView gv){
	public void setParent(setStartTime gv){
		Parent=gv;
	}
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(8, 11, 211, 15));
			jLabel.setText("Full format : Y/M/D h:m:s  ");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJTextFieldTime(), null);
			jContentPane.add(jLabel, null);
			jContentPane.add(getJButtonOK(), null);
			jContentPane.add(getJButtonCancel(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jTextFieldTime	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldTime() {
		if (jTextFieldTime == null) {
			jTextFieldTime = new JTextField();
			jTextFieldTime.setBounds(new Rectangle(7, 31, 216, 30));
		}
		return jTextFieldTime;
	}

	public void setTime(wintime tm){
		CurrentTime = tm;
		jTextFieldTime.setText(tm.fmt());
	}
	//-------------------------------------------------------------------
	private boolean parseTimeString(String txt){
		wintime tm = new wintime(CurrentTime);
		int ret = tm.parseDaySec(txt);
		if(ret !=0) {
			CurrentTime = tm;
			return true;
		}
		return false;
	}
	/**
	 * This method initializes jButtonOK	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonOK() {
		if (jButtonOK == null) {
			jButtonOK = new JButton();
			jButtonOK.setBounds(new Rectangle(143, 84, 75, 25));
			jButtonOK.setText("Apply");
			jButtonOK.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if(parseTimeString(jTextFieldTime.getText())){
						Parent.setDispTimeStart(CurrentTime);
					}
				}
			});
		}
		return jButtonOK;
	}

	/**
	 * This method initializes jButtonCancel	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancel() {
		if (jButtonCancel == null) {
			jButtonCancel = new JButton();
			jButtonCancel.setBounds(new Rectangle(11, 84, 75, 25));
			jButtonCancel.setText("Cancel");
			jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					setVisible(false);
				}
			});
		}
		return jButtonCancel;
	}


}  //  @jve:decl-index=0:visual-constraint="10,10"
